/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package index;

import java.io.File;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import stemmer.Stemmer;

/**
 *
 * @author Lu
 */
public class ElementTypeHandler extends DefaultHandler {

    private ArrayList<String> typeList;
    private String currentElementType;

    public ElementTypeHandler() {
        super();
        typeList = new ArrayList<String>();
    }


    private boolean typeIndexed(String type) {
        if (typeList.size() == 0) {
            return false;
        }
        for (int i = typeList.size() - 1; i > -1; i--) {
            if (typeList.get(i).compareToIgnoreCase(type) == 0) {
                return true;
            }
        }
        return false;
    }
    // balise detection
// WARNING this only works if a "balise" can only be on one depth

    @Override
    public void startElement(String uri, String localName,
            String qName, Attributes attributes) throws SAXException {

        // if the type is already indexed
        if (!typeIndexed(qName)) {
            // we get its index
            typeList.add(qName);
        }

    }

    // end balise detection
    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {

    }


    //détection de caractères
    @Override
    public void characters(char[] ch, int start, int length)
            throws SAXException {

    }

    //début du parsing
    @Override
    public void startDocument() throws SAXException {
    }
    //fin du parsing

    @Override
    public void endDocument() throws SAXException {
    }

    public ArrayList<String> getTypeList() {
        return typeList;
    }
}
